package com.naizhuai.Model;

import android.text.TextUtils;
import com.naizhuai.AppContext;
import com.naizhuai.Model.db.user.PersonUserBean;
import com.naizhuai.ui.entity.management.CompanyBean;
import com.naizhuai.ui.entity.management.DepartmentBean;
import com.naizhuai.util.ConstantsPersonResources;
import com.naizhuai.util.NaizhuAILog;

/**
 * email：525603977@qq.com
 * Fighting
 * 账户辅助类，
 * 用于更新用户信息和保存当前账户等操作
 */
public final class AccountHelper {

    public static boolean isLogin(){
       return !TextUtils.isEmpty(getUid())&&
               !ConstantsPersonResources.SESSION_ID_DEFAULT_VALUE.equals(getSid());
    }

    public static void login(String uid,String sid){
        AppContext.setSpValue(PersonUserBean.USER_ID_KEY, uid);
        AppContext.setSpValue(ConstantsPersonResources.SESSION_ID_KEY, sid);
    }


    public static String getUid(){
        String uid=AppContext.getSpValue(PersonUserBean.USER_ID_KEY,"");
        return uid;
    }
    private static String getSid(){
        String sid=AppContext.getSpValue(ConstantsPersonResources.SESSION_ID_KEY,ConstantsPersonResources.SESSION_ID_DEFAULT_VALUE);
        return sid;
    }

    public static String getComPanyid(){
        String conpanyid=AppContext.getSpValue(CompanyBean.COMPANY_ID_KEY,"");
        return conpanyid;
    }
    public static String getDepartmentid(){
        String departmentid=AppContext.getSpValue(DepartmentBean.DEPARTMENT_ID_KEY,"");
        return departmentid;
    }
    public static void removeComPanyid(){
       AppContext.getEditor().remove(CompanyBean.COMPANY_ID_KEY).apply();
    }
    public static void  saveComPany(PersonUserBean userBean){
        AppContext.getEditor()
                .putString(CompanyBean.COMPANY_NAME_KEY, userBean.getCompanyName())
                .putString(CompanyBean.COMPANY_ID_KEY, userBean.getCompanyId())
                .putString(DepartmentBean.DEPARTMENT_ID_KEY, userBean.getDepartmentId())
                .apply();
    }
    public static void  removeComPany(){
        AppContext.getEditor()
                .remove(CompanyBean.COMPANY_NAME_KEY)
                .remove(CompanyBean.COMPANY_ID_KEY)
                .remove(DepartmentBean.DEPARTMENT_ID_KEY)
                .apply();
    }
    public static void logout(){
        AppContext.getEditor()
                .remove(PersonUserBean.USER_ID_KEY)
                .remove(ConstantsPersonResources.SESSION_ID_KEY)
                .remove(CompanyBean.COMPANY_NAME_KEY)
                .remove(CompanyBean.COMPANY_ID_KEY)
                .remove(DepartmentBean.DEPARTMENT_ID_KEY)
                .apply();
    }
}
